package com.ruoyi.personnel.management.staff.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.personnel.management.staff.domain.Staff;
import com.ruoyi.personnel.management.staff.domain.StaffLeaveRecord;
import com.ruoyi.personnel.management.staff.domain.StaffReinstateRecord;
//import com.ruoyi.personnel.management.staff.domain.StaffTransferRecord;
import com.ruoyi.personnel.management.staff.domain.StaffTransferRecord;
import com.ruoyi.personnel.management.staff.service.IStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 员工信息
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/personnel/staff")
@Api(value = "员工信息模块", tags = "员工信息接口")
public class StaffController extends BaseController {
    @Autowired
    private IStaffService staffService;


    /**
     * 获取员工列表
     * @param staff
     * @return
     */
    @ApiOperationSupport(includeParameters = {"Staff.staffId", "Staff.staffName", "Staff.staffHireDate"})
    @ApiOperation(value = "获取员工列表",notes = "查询所有员工信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Staff staff) {
        startPage();
        List<Staff> staffList = staffService.selectStaffList(staff);
        return getDataTable(staffList);
    }

    /**
     * 导出员工
     *
     * @param staff
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody Staff staff) {
        List<Staff> list = staffService.selectStaffList(staff);
        ExcelUtil<Staff> util = new ExcelUtil<Staff>(Staff.class);
        return util.exportExcel(list, "员工数据");
    }

    /**
     * 新增员工
     *
     * @param staff
     * @return
     */
    @ApiOperation(value = "新增员工", notes = "新增员工")
    @ApiImplicitParam(name = "staff", value = "新增员工", dataType = "Staff")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody Staff staff) {
        Staff latestStaff = staffService.selectLatestStaff();
        staff.setStaffId(latestStaff.getStaffId());
        return toAjax(staffService.insertStaff(staff));
    }

    /**
     * 修改员工
     *
     * @param staff
     * @return
     */
    @ApiOperation(value = "修改员工", notes = "修改员工")
    @ApiImplicitParam(name = "staff", value = "修改员工", dataType = "Staff")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody Staff staff) {
        return toAjax(staffService.updateStaff(staff));
    }

    /**
     * 删除员工
     * 仅修改删除标志位
     *
     * @param staff
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Staff staff) {

        return toAjax(staffService.updateStaffDeleteFlag(staff));
    }


    /**
     * 查询员工离职记录
     * @param staffLeaveRecord
     * @return
     */
    @ApiOperationSupport(includeParameters = {"StaffLeaveRecord.staffId", "StaffLeaveRecord.staffName", "StaffLeaveRecord.staffLeaveDate"})
    @ApiOperation(value = "查询员工离职记录",notes = "查询员工离职记录")
    @PostMapping("/selectStaffLeaveRecord")
    public TableDataInfo selectStaffLeaveRecord(@RequestBody StaffLeaveRecord staffLeaveRecord) {
        startPage();
        List<StaffLeaveRecord> staffLeaveRecords = staffService.selectStaffLeaveRecordList(staffLeaveRecord);
        return getDataTable(staffLeaveRecords);
    }

    /**
     * 查询员工复职记录
     * @param staffReinstateRecord
     * @return
     */
    @ApiOperationSupport(includeParameters = {"StaffReinstateRecord.staffId", "StaffReinstateRecord.staffName", "StaffReinstateRecord.staffReinstateDate"})
    @ApiOperation(value = "查询员工复职记录",notes = "查询员工复职记录")
    @PostMapping("/selectStaffReinstateRecord")
    public TableDataInfo selectStaffReinstateRecord(@RequestBody StaffReinstateRecord staffReinstateRecord) {
        startPage();
        List<StaffReinstateRecord> staffReinstateRecords = staffService.selectStaffReinstateRecordList(staffReinstateRecord);
        return getDataTable(staffReinstateRecords);
    }

    /**
     * 查询员工调动记录
     * @param staffTransferRecord
     * @return
     */
    @ApiOperationSupport(includeParameters = {"StaffTransferRecord.staffId", "StaffTransferRecord.staffName", "StaffTransferRecord.transferTime"})
    @ApiOperation(value = "查询员工调动记录",notes = "查询员工调动记录")
    @PostMapping("/selectStaffTransferRecord")
    public TableDataInfo selectStaffReinstateRecord(@RequestBody StaffTransferRecord staffTransferRecord) {
        startPage();
        List<StaffTransferRecord> staffTransferRecords = staffService.selectStaffTransferRecordList(staffTransferRecord);
        return getDataTable(staffTransferRecords);
    }
}
